﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Diagnostics;

namespace PetriNetSharp.Converter
{
	/// <summary>
	/// Value converter for inverting the value of a boolean
	/// </summary>
	class InvertBooleanValueConverter : IValueConverter
	{
		/// <summary>
		/// Convert a passed boolean to its opposite value
		/// </summary>
		/// <param name="value">The boolean to invert</param>
		/// <param name="targetType">Not used</param>
		/// <param name="parameter">Not used</param>
		/// <param name="culture">Not used</param>
		/// <returns>A boolean of the opposite value</returns>
		/// <preconditions>
		/// Value must be of type boolean
		/// </preconditions>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			#region preconditions
			Debug.Assert(value is Boolean, "InvertBooleanConvert passed value not of type Boolean",
				"InvertBooleanValueConverter Convert was called with parameter value not being of type Boolean");
			#endregion

			bool val = (bool)value;

			return !val;
		}

		/// <summary>
		/// Convert back a passed boolean to its opposite value
		/// </summary>
		/// <param name="value">The boolean to invert</param>
		/// <param name="targetType">Not used</param>
		/// <param name="parameter">Not used</param>
		/// <param name="culture">Not used</param>
		/// <returns>A boolean of the opposite value</returns>
		/// <preconditions>
		/// Value must be of type boolean
		/// </preconditions>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			#region preconditions
			Debug.Assert(value is Boolean, "InvertBooleanConvert passed value not of type Boolean",
				"InvertBooleanValueConverter ConvertBack was called with parameter value not being of type Boolean");
			#endregion

			bool val = (bool)value;

			return !val;
		}

	}
}
